/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.courier.view;

import com.sun.courier.dal.EmployeeDAL;
import com.sun.courier.dal.GetStatusCourierDAL;
import com.sun.courier.entity.CourierManage;
import com.sun.courier.entity.Employee;
import com.sun.courier.entity.Courier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author NamBH
 */
public class DialogStatusCourier extends javax.swing.JDialog {

    /**
     * Creates new form dialogDemoCourier
     */
    private EmployeeDAL dalEmployee = new EmployeeDAL();
    private ArrayList<CourierManage> lstCourier;
    private ArrayList<Courier> lstGetCourier;
    private GetStatusCourierDAL dalCourier = new GetStatusCourierDAL();
    private EditTablModel model;
    private GetEmployee DialogEmp;

    public DialogStatusCourier(java.awt.Frame parent, boolean modal, ArrayList<CourierManage> lstCourier) {
        super(parent, modal);
        initComponents();
        this.lstCourier = lstCourier;
        loadTable();
    }
    
      private void loadTable() {
        Vector cols = new Vector();
        cols.add("Step");
        cols.add("Status");
        cols.add("Current Position");
        cols.add("Description");
        cols.add("Update time");

        Vector data = new Vector();
        int i = 0;
        for (CourierManage entity : lstCourier) {
            Vector row = new Vector();
            String CurrentPosition = "";
            String statusDes = "";
            
            switch (entity.getStatus()) {
                case 1:
                    statusDes = "Receive From Customer";
                    break;
                case 2:
                    statusDes = "Sending Courier To Starting Store";
                    break;
                case 3:
                    statusDes = "Send Courier To Despatching";
                    break;
                case 4:
                    statusDes = "Sending Courier To Destination Store";
                    break;
                case 5:
                    statusDes = "Sending Courier To Return EmployeeSending Courier To Returning Employee";
                    break;
                case 6:
                    statusDes = "Courier In Store";
                    break;
                case 7:
                    statusDes = "Courier In Despatching";
                    break;
                case 8:
                    statusDes = "Courier In Destination Store";
                    break;
                case 9:
                    statusDes = "Returning Employee Returned Customer";
                    break;
                case 10:
                    statusDes = "Sending Courier To Return Employee";
                    break;
            }
            switch (entity.getCurrentPosition()) {
                case 0:
                    CurrentPosition = "Sent";
                    break;
                case 1:
                    CurrentPosition = "Available";
                    break;
            }
            row.add(++i);
            row.add(statusDes);
            row.add(CurrentPosition);
            row.add(entity.getDescription());
            row.add(entity.getUpdatetime());

            data.add(row);
        }
        model = new EditTablModel(data, cols);
        tblItem.setModel(model);
        
        tblItem.getColumnModel().getColumn(0).setMaxWidth(50);
        tblItem.getColumnModel().getColumn(0).setMinWidth(50);
        
        tblItem.getColumnModel().getColumn(2).setMaxWidth(80);
        tblItem.getColumnModel().getColumn(2).setMinWidth(80);
        
        tblItem.setRowHeight(30);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnOKDL = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblItem = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Status Courier");

        btnOKDL.setText("OK");
        btnOKDL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKDLActionPerformed(evt);
            }
        });

        tblItem.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblItemMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblItem);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(btnOKDL, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(306, 306, 306))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(302, 302, 302))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnOKDL)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKDLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKDLActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnOKDLActionPerformed

    private void tblItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblItemMouseClicked

            GetEmployee emp = new GetEmployee(new JFrame(), true);
            emp.setLocation(450, 250);
            emp.setVisible(true);
    }//GEN-LAST:event_tblItemMouseClicked
  class GetEmployee extends JDialog{
        public GetEmployee(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        cbxItem = new javax.swing.JComboBox();
        newJdialog = new javax.swing.JLabel();
        btOkNewDialog = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        cbxItem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sender", "Receiver" }));

        newJdialog.setText("Get About Employee :");

        btOkNewDialog.setText("Ok");
        btOkNewDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOkNewDialogActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(newJdialog)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btOkNewDialog, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbxItem, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbxItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(newJdialog))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(btOkNewDialog))
        );

        pack();
    }// </editor-fold>                        

    private void btOkNewDialogActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
      int cbItem = cbxItem.getSelectedIndex();
        int row = tblItem.getSelectedRow();
            switch (cbItem) {
                case 0:
                    if (row >= 0) {
                        int i = lstCourier.get(row).getSender();
                        if (i != 1) {
                            ArrayList<Employee> entitys = dalEmployee.getById(i);
                            DialogAboutEmployee dlgCourier = new DialogAboutEmployee(new JFrame(), true, entitys);
                            this.setVisible(false);
                            dlgCourier.setLocation(400, 200);
                            dlgCourier.setVisible(true);
                        } else {                 
                            ArrayList<Courier> entitys = dalCourier.getById(lstCourier.get(row).getCourierId());
                            DialogAboutEmployee1 dlgCourier = new DialogAboutEmployee1(new JFrame(), true, entitys);
                            this.setVisible(false);
                            dlgCourier.setLocation(400, 200);
                            dlgCourier.setVisible(true);
                        }
                    }
                    break;
                case 1:
                    if (row >= 0) {
                        ArrayList<Employee> entitys = dalEmployee.getById(lstCourier.get(row).getReceiver());
                        DialogAboutEmployee dlgCourier = new DialogAboutEmployee(new JFrame(), true, entitys);
                        this.setVisible(false);
                        dlgCourier.setLocation(400, 200);
                        dlgCourier.setVisible(true);

                    }
                    break;
            }
        }
    // Variables declaration - do not modify                     
    private javax.swing.JButton btOkNewDialog;
    private javax.swing.JComboBox cbxItem;
    private javax.swing.JLabel newJdialog;
    }
    
    // <editor-fold defaultstate="collapsed" desc="EditTable">                          
    private class EditTablModel extends DefaultTableModel {

        boolean[] columnEditable;

        public EditTablModel(Vector data, Vector columnNames) {
            super(data, columnNames);
            columnEditable = new boolean[columnNames.size()];
            Arrays.fill(columnEditable, false);
        }

        public boolean isCellEditable(int row, int column) {
            if (!columnEditable[column]) {
                return false;
            } else {
                return super.isCellEditable(row, column);
            }
        }

        public void setColumnEditable(int column, boolean editable) {
            columnEditable[column] = editable;
        }

        public boolean getColumnEditable(int column) {
            return columnEditable[column];
        }
    }//</editor-fold>
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOKDL;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblItem;
    // End of variables declaration//GEN-END:variables

  

    
   
}
//